function _init(){

	var _seasonId = $('#seasonId').val();
	var _zoneId = $('#zoneId').val();
	var _schoolId = $('#schoolId').val();
	var _teamId = $('#teamId').val();
	var _time = $('#_time').val();
	if(_seasonId != ''){
		//var _seasonValue = $('_season').next().find("li[value="+_seasonId+"]");
		$('#_season').attr('value',_seasonId);
		$('#_season').text($('#_season').next().find("li[value="+_seasonId+"]").text());
	}
	if(_zoneId != ''){
		//var _seasonValue = $('_season').next().find("li[value="+_seasonId+"]");
		checkZone(_zoneId,_schoolId,_teamId);
		$('#_zone').attr('value',_zoneId);
		$('#_zone').text($('#_zone').next().find("li[value="+_zoneId+"]").text());
	}
	if(_time != ''){
		$('#s_time').val(_time);
	}
}

$(function(){
	//有回显数据时，页面初始化
	_init();
	$('.score-search').click(function(){
		var _seasonId = $('#_season').attr('value');
		var _zone = $('#_zone').attr('value');
		var _school = $('#_school').attr('value');
		var _team = $('#_team').attr('value');
		var _time = $('#s_time').val();
		var url = "/frontScore/show.html?seasonId="+_seasonId
					+"&zoneId="+_zone
					+"&schoolId="+_school
					+"&teamId="+_team
					+"&_time="+_time;
		window.location.href = url;
	});
	
	//根据赛区查学校
	$('.zoneId').click(function(){
		var zoneId = $(this).val();
		checkZone(zoneId);
	});
});

function checkZone(zoneId,_schoolId,_teamId){
	$('#_team').attr('value','');
	$('#_team').text('请选择');
	$.post('/frontScore/querySchoolByzoneId.yson',
			{zoneId : zoneId},
			function(data){
				var schoolSelect = "";
				$(data).each(function (i, obj) {
					schoolSelect += "<li id='schoolId" + i + "' onclick='checkSchool(" + i + ")' "
					+ "onmousemove='mouseMoveSchool(" + i + ")' onmouseout='mouseOutSchool("
					+ i + ")' " + "value=" + obj.id + ">" + obj.name + "</li>";
				});
				$("#schoolUi").empty().append(schoolSelect);
				$('#_school').attr('value',_schoolId);
				$('#_school').text($('#_school').next().find("li[value="+_schoolId+"]").text());
				var i = $('#_school').next().find("li[value="+_schoolId+"]").attr('id').split('schoolId')[1];
				checkSchool(i,_teamId);
			},"JSON");
}
function checkSchool(i,_teamId){
	$("#schoolId"+i+"").parent().slideToggle('fast').parent().find('.sellight').text($("#schoolId"+i+"").text());
	$("#schoolId"+i+"").parent().parent().find('.sellight').attr('value',$("#schoolId"+i+"").attr('value'));
	var schoolLiId=$("#schoolId"+i+"").val();
	$('#schoolUi').hide();
	$.ajax({
        url: '/playerDate/queryTeamBySchoolId.yson',
        type: 'post',
        dataType: "json",
        data: {schoolId: schoolLiId},
        success: function (data) {
            var teamSelect = "";
            $(data).each(function (i, obj) {
            	teamSelect +="<li id='teamLiId"+i+"' onclick='checkTeam("+i+")' " +
                		     "onmousemove='mouseMoveTeam("+i+")' onmouseout='mouseOutTeam("+i+")' " +
                		     "value=" + obj.id + ">" + obj.name + "</li>";
            });
            $("#teamUi").empty().append(teamSelect);
            $('#_team').attr('value',_teamId);
    		$('#_team').text($('#_team').next().find("li[value="+_teamId+"]").text());
        }
    });
}

function checkTeam(i){
	$("#teamLiId"+i+"").parent().slideToggle('fast').parent().find('.sellight').text($("#teamLiId"+i+"").text());
	$("#teamLiId"+i+"").parent().parent().find('.sellight').attr('value',$("#teamLiId"+i+"").attr('value'));
}
function mouseMoveZone(i){
	$("#cityLiId"+i+"").addClass('hovon');
}
	
function mouseOutZone(i){
	$("#cityLiId"+i+"").removeClass('hovon');
}

function mouseMoveSchool(i){
	$("#schoolId"+i+"").addClass('hovon');
}

function mouseOutSchool(i){
	$("#schoolId"+i+"").removeClass('hovon');
}

function mouseMoveTeam(i){
	$("#teamLiId"+i+"").addClass('hovon');
}

function mouseOutTeam(i){
	$("#teamLiId"+i+"").removeClass('hovon');
}